package com.example.springcloudwinter.controller;


import com.example.springcloudwinter.dto.ResultEntity;
import com.example.springcloudwinter.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

@RefreshScope
@RestController
@RequestMapping("/order")
public class OrderController {
    
    @Autowired
    private OrderService orderService;
    
    @GetMapping("/list")
    public ResultEntity<?> listOrdersByUserId(@RequestParam("userId")String userId){
        return orderService.getHistoryOrderList(userId);
    }
    
    @GetMapping("/{orderId}")
    public ResultEntity<?> getOrdersById(@PathVariable("orderId")int id,@RequestParam("userId")String userId){
        return orderService.getOrderById(id,userId);
    }
    
    @PostMapping("/create")
    public ResultEntity<?> createOrders(@RequestParam("userId")String userId, @RequestParam("businessId")int businessId,
                                        @RequestParam("daId")int addressId, @RequestParam("orderTotal")double orderTotal
    ){
        return orderService.createOrder(userId,businessId,orderTotal,addressId);
    }
    
    @GetMapping("/updatePoint")//待改进
    public ResultEntity<?> updatePoint(@RequestParam("orderId")int orderId,@RequestParam("remainPoint")int remainPoint){
        return orderService.updatePoint(orderId,remainPoint);
    }
    
}